var Settings = {

    /* Function init
     * @param void
     * @return void
     * @access public
     * */
    init:function(){
        var self = this;

        /* When the user clicks on the save button of the configuration window*/
        $('#system-configuration-form').submit(function(){
            self.saveSystemConfig();
            return false;
        });
    },

    saveSystemConfig: function(){
        var self = this;
        jLib.showFormLoading();
        /* Preparation of the data to send to the server to be processed. Here we retrieve the data from the login form. */
        var query = 'model=SystemConfig&'+ $('#system-configuration-form').serialize();
        var url  = $('#system-configuration-form').attr('action');
        /* Send the data to the server and handle the server response */
        $.ajax({
            url:url,
            data:query,
            dataType:'json',
            type:'POST',
            success:function (response) {
                var txt = '';
                if (typeof response.mesg == 'object') {
                    for (megTxt in response.mesg) {
                        txt += response.mesg[megTxt] + '<br />';
                    }
                }
                else {
                    txt = response.mesg
                }
                jLib.hideFormLoading();
                //* When everything went on smoothly on the server redirect the user to the appropriate page.*//*


                if (response.code === 0) {
                    jLib.message(txt, 'success');
                }
                //* When there are Errors *//*
                else if (response.code === 1) {
                    jLib.serverError(txt);
                }
            },
            error:function (xhr) {
                console.log(xhr.responseText);
                jLib.serverError();
            }
        });
    }

};


/* when the page is loaded */
$(document).ready(function() {
    Settings.init();
});